package top.xzxsrq.web.utils;

import lombok.extern.log4j.Log4j2;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RestController;

import java.lang.reflect.Modifier;

@Log4j2
public class SpringUtils {
    public static String hasSpringAnnotation(Class<?> clazz) {
        if (clazz == null) {
            return "pass";
        }
        //是否是接口
        if (clazz.isInterface()) {
            return "pass";
        }
        //是否是抽象类
        if (Modifier.isAbstract(clazz.getModifiers())) {
            return "pass";
        }
        //常规注解效验和处理
        try {
            if (clazz.getAnnotation(Component.class) != null) {
                return "Component";
            }
            if (clazz.getAnnotation(Repository.class) != null) {
                return "Repository";
            }
            if (clazz.getAnnotation(Service.class) != null) {
                return "Service";
            }
            if (clazz.getAnnotation(Configuration.class) != null) {
                return "Configuration";
            }
            if (clazz.getAnnotation(Controller.class) != null || clazz.getAnnotation(RestController.class) != null) {
                return "Controller";
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return "pass";
    }

}
